package com.love.labuladong;

/**
 * @Author : zh
 * @Description : 最长回文字串
 * @Date : 2024-06-24 13:08
 */
public class LongestPalindrome {

    public static void main(String[] args) {
//        String s = "a";
        String s = "babad";
        String s1 = longestPalindrome(s);
        System.out.println(s1);

    }

    public static String longestPalindrome(String s) {
        char[] arr = s.toCharArray();
        int L = 0;
        String res = "";
        while(L <= arr.length - 1){
            int f = L;
            int e = arr.length - 1;
            int RT = 0;
            while (f <= e){
                if(arr[f] == arr[e] ){
                    f++;
                    RT = Math.max(e - L + 1, RT);
                    e--;
                }
                e--;
            }

            if(e - f <= 1 && RT > 0){
                res = (RT  - res.length()) > 0 ? new String(arr,L,RT ) : res;
            }
            L++;
        }
        return res;
    }

}
